﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PersonalAccounting.Controls
{
    public partial class IntegerTextBox : TextBox
    {
        public IntegerTextBox()
        {
            InitializeComponent();
        }

        public IntegerTextBox(Container container)
        {
            container.Add(this);
            InitializeComponent();
        }


        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (e.KeyChar > 10)
            {
                if (e.KeyChar < '0' || e.KeyChar > '9')
                    e.Handled = true;
            }
        }

        public int Value
        {
            get
            {
                try
                {
                    return int.Parse(Text);
                }
                catch
                {
                    return 0;
                }
            }
            set { Text = value.ToString(); }
        }

    }
}